package com.yiwenup.log.listener;

import org.slf4j.MDC;
import org.springframework.boot.context.event.ApplicationEnvironmentPreparedEvent;
import org.springframework.context.ApplicationListener;
import org.springframework.core.env.ConfigurableEnvironment;
import org.springframework.lang.NonNull;

/**
 * SpringApplicationEvent监听
 **/
public class SpringApplicationEventListener implements ApplicationListener<ApplicationEnvironmentPreparedEvent> {

    /**
     * log4j2.xml取值key
     */
    public static final String APP_NAME = "appName";

    @Override
    public void onApplicationEvent(@NonNull ApplicationEnvironmentPreparedEvent event) {
        ConfigurableEnvironment environment = event.getEnvironment();
        String appName = environment.getProperty("spring.application.name", String.class, "service");
        // MDC.put(APP_NAME, appName);
    }
}
